{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "import time\n",
    "import random\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(15000, 160)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train = pd.read_csv('../data/train_xy.csv')\n",
    "train.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10000, 159)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test = pd.read_csv('../data/train_x.csv')\n",
    "test.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(15000, 157)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_train = train.drop(['cust_id','cust_group','y'],axis=1)\n",
    "x_train.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10000, 157)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_test = test.drop(['cust_id','cust_group'],axis=1)\n",
    "x_test.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x21e2aa184a8>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPkAAADuCAYAAAD7nKGzAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAGE1JREFUeJzt3XmYFNW9xvHv6Z5hZlhlXwQtFAUV\nRRRjFBGuihgKlxi9KipkMYlGk3hjTOpeE4PJVSsxV2NyTW6iYlRc467lIxrAHRWXqGDYgqUi6rDO\nMDPM0t11/6hGWQamZ6a7T9Xp3+d55hkemO5+h2feOaeqT51SQRAghDBXQncAIURhScmFMJyUXAjD\nScmFMJyUXAjDScmFMJyUXAjDScmFMJyUXAjDScmFMJyUXAjDScmFMJyUXAjDScmFMJyUXAjDScmF\nMJyUXAjDScmFMJyUXAjDScmFMJyUXAjDScmFMJyUXAjDScmFMJyUXAjDScmFMJyUXAjDScmFMJyU\nXAjDScmFMFyZ7gCiOCzH6wkMA/oA5UCXHT5v/XMaqM1+1AAbgWrftWs1xBZ5oOT+5GawHK8LcAhw\nAGGZ98p+bP1zz06+RCNQDXwE/BNYsvXDd+01nXxuUUBS8hiyHE8B+wFfAo7Mfh4DVGiKtImw8O8B\nbwLzfdderimL2IGUPCYsxzsEsIFJwBFAb62B2vYhMA/4O/B337WrNecpWVLyiLIcrxw4HjiVsNzD\n9CbqlABYTFj4R4HnfdeWH7wikZJHiOV4SWAKcCZhuaM+WnfUB8Ac4HbftVfoDmM6KXkEWI43EPg2\n8F1gqOY4xfYKcAdwr+/aG3WHMZGUXCPL8cYDFwNfI3z7qpQ1AY8Dv/dd+wXdYUwiJS8yy/G6AucS\nlnuM5jhR9QpwHfCI79oZ3WHiTkpeJNn3sS8ErgAGaI4TF8uAq4G7fddO6w4TV1LyArMcLwGcB1wF\n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IQwnJRfCcFJyIQwnJRfCcFJyIQwnJRfCcFJyIQwnJRfCcFJyIQwnJRfCcFJyIQwn\nJRfCcFJyIQwnJRfCcFJyIQwnJRfCcFJyIQwnJRfCcFJyIQz3/zbtcAuj3nkLAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "train['y'].value_counts().plot.pie(autopct = '%1.2f%%')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(25000, 157)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = pd.concat([x_train,x_test])\n",
    "x.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "Y_train = train['y']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "for i in range(96,158):\n",
    "    col = 'x'+'_'+str(i)\n",
    "    if col in x.columns.values:\n",
    "        dummies_df = pd.get_dummies(x[col]).rename(columns=lambda x: col + str(x))\n",
    "        x = pd.concat([x, dummies_df], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(15000, 361)\n",
      "(10000, 361)\n"
     ]
    }
   ],
   "source": [
    "train_X = x[0:15000]\n",
    "test_X = x[15000:25000]\n",
    "print(train_X.shape)\n",
    "print(test_X.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "from sklearn.svm import SVC\n",
    "from sklearn import metrics  #accuracy_score,recall_score,f1_score\n",
    "from sklearn.metrics import classification_report\n",
    "from sklearn.metrics import precision_recall_fscore_support\n",
    "from sklearn.utils.multiclass import unique_labels\n",
    "from sklearn.metrics import accuracy_score\n",
    "from sklearn import model_selection\n",
    "from sklearn.cross_validation import cross_val_score\n",
    "from sklearn.model_selection import train_test_split, GridSearchCV, KFold\n",
    "from sklearn.svm import LinearSVC\n",
    "from sklearn import linear_model\n",
    "from xgboost import XGBClassifier\n",
    "from lightgbm import LGBMClassifier\n",
    "\n",
    "from keras.models import Model\n",
    "from keras.layers import Dense, Input"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/50\n",
      "15000/15000 [==============================] - 2s 139us/step - loss: 1630.7941\n",
      "Epoch 2/50\n",
      "15000/15000 [==============================] - 2s 113us/step - loss: 1629.4037\n",
      "Epoch 3/50\n",
      "15000/15000 [==============================] - 2s 112us/step - loss: 1629.2613\n",
      "Epoch 4/50\n",
      "15000/15000 [==============================] - 2s 115us/step - loss: 1629.2614\n",
      "Epoch 5/50\n",
      "15000/15000 [==============================] - 2s 113us/step - loss: 1629.2615\n",
      "Epoch 6/50\n",
      "15000/15000 [==============================] - 2s 114us/step - loss: 1629.2615\n",
      "Epoch 7/50\n",
      "15000/15000 [==============================] - 2s 118us/step - loss: 1629.2616\n",
      "Epoch 8/50\n",
      "15000/15000 [==============================] - 2s 116us/step - loss: 1629.2616\n",
      "Epoch 9/50\n",
      "15000/15000 [==============================] - 2s 115us/step - loss: 1629.2616\n",
      "Epoch 10/50\n",
      "15000/15000 [==============================] - 2s 116us/step - loss: 1629.2616\n",
      "Epoch 11/50\n",
      "15000/15000 [==============================] - 2s 118us/step - loss: 1629.2616\n",
      "Epoch 12/50\n",
      "15000/15000 [==============================] - 2s 117us/step - loss: 1629.2617\n",
      "Epoch 13/50\n",
      "15000/15000 [==============================] - 2s 126us/step - loss: 1629.2616\n",
      "Epoch 14/50\n",
      "15000/15000 [==============================] - 2s 130us/step - loss: 1629.2616\n",
      "Epoch 15/50\n",
      "15000/15000 [==============================] - 2s 120us/step - loss: 1629.2616\n",
      "Epoch 16/50\n",
      "15000/15000 [==============================] - 2s 124us/step - loss: 1629.2616\n",
      "Epoch 17/50\n",
      "15000/15000 [==============================] - 2s 116us/step - loss: 1629.2616\n",
      "Epoch 18/50\n",
      "15000/15000 [==============================] - 2s 116us/step - loss: 1629.2616\n",
      "Epoch 19/50\n",
      "15000/15000 [==============================] - 2s 119us/step - loss: 1629.2616\n",
      "Epoch 20/50\n",
      "15000/15000 [==============================] - 2s 118us/step - loss: 1629.2616\n",
      "Epoch 21/50\n",
      "15000/15000 [==============================] - 2s 116us/step - loss: 1629.2616\n",
      "Epoch 22/50\n",
      "15000/15000 [==============================] - 2s 117us/step - loss: 1629.2616\n",
      "Epoch 23/50\n",
      "15000/15000 [==============================] - 2s 117us/step - loss: 1629.2616\n",
      "Epoch 24/50\n",
      "15000/15000 [==============================] - 2s 117us/step - loss: 1629.2616\n",
      "Epoch 25/50\n",
      "15000/15000 [==============================] - 2s 117us/step - loss: 1629.2616\n",
      "Epoch 26/50\n",
      "15000/15000 [==============================] - 2s 118us/step - loss: 1629.2616\n",
      "Epoch 27/50\n",
      "15000/15000 [==============================] - 2s 116us/step - loss: 1629.2616\n",
      "Epoch 28/50\n",
      "15000/15000 [==============================] - 2s 116us/step - loss: 1629.2616\n",
      "Epoch 29/50\n",
      "15000/15000 [==============================] - 2s 118us/step - loss: 1629.2616\n",
      "Epoch 30/50\n",
      "15000/15000 [==============================] - 2s 118us/step - loss: 1629.2616\n",
      "Epoch 31/50\n",
      "15000/15000 [==============================] - 2s 117us/step - loss: 1629.2616\n",
      "Epoch 32/50\n",
      "15000/15000 [==============================] - 2s 117us/step - loss: 1629.2616\n",
      "Epoch 33/50\n",
      "15000/15000 [==============================] - 2s 116us/step - loss: 1629.2616\n",
      "Epoch 34/50\n",
      "15000/15000 [==============================] - 2s 117us/step - loss: 1629.2616\n",
      "Epoch 35/50\n",
      "15000/15000 [==============================] - 2s 116us/step - loss: 1629.2617\n",
      "Epoch 36/50\n",
      "15000/15000 [==============================] - 2s 117us/step - loss: 1629.2616\n",
      "Epoch 37/50\n",
      "15000/15000 [==============================] - 2s 116us/step - loss: 1629.2616\n",
      "Epoch 38/50\n",
      "15000/15000 [==============================] - 2s 123us/step - loss: 1629.2616\n",
      "Epoch 39/50\n",
      "15000/15000 [==============================] - 2s 118us/step - loss: 1629.2616\n",
      "Epoch 40/50\n",
      "15000/15000 [==============================] - 2s 119us/step - loss: 1629.2616\n",
      "Epoch 41/50\n",
      "15000/15000 [==============================] - 2s 118us/step - loss: 1629.2616\n",
      "Epoch 42/50\n",
      "15000/15000 [==============================] - 2s 119us/step - loss: 1629.2616\n",
      "Epoch 43/50\n",
      "15000/15000 [==============================] - 2s 118us/step - loss: 1629.2616\n",
      "Epoch 44/50\n",
      "15000/15000 [==============================] - 2s 117us/step - loss: 1629.2616\n",
      "Epoch 45/50\n",
      "15000/15000 [==============================] - 2s 118us/step - loss: 1629.2617\n",
      "Epoch 46/50\n",
      "15000/15000 [==============================] - 2s 117us/step - loss: 1629.2616\n",
      "Epoch 47/50\n",
      "15000/15000 [==============================] - 2s 118us/step - loss: 1629.2616\n",
      "Epoch 48/50\n",
      "15000/15000 [==============================] - 2s 116us/step - loss: 1629.4557\n",
      "Epoch 49/50\n",
      "15000/15000 [==============================] - 2s 119us/step - loss: 1629.1000\n",
      "Epoch 50/50\n",
      "15000/15000 [==============================] - 2s 118us/step - loss: 1629.0222\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x21e530a9320>"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "encoding_dim = 200\n",
    "input_dim = Input(shape=(361,))\n",
    "\n",
    "encoded = Dense(361, activation='linear')(input_dim)\n",
    "# encoded = Dense(300, activation='relu')(encoded)\n",
    "# encoded = Dense(32, activation='relu')(encoded)\n",
    "encoder_output = Dense(encoding_dim)(encoded)\n",
    "\n",
    "decoded = Dense(200, activation='relu')(encoder_output)\n",
    "# decoded = Dense(64, activation='relu')(decoded)\n",
    "# decoded = Dense(128, activation='relu')(decoded)\n",
    "decoded = Dense(361, activation='tanh')(decoded)\n",
    "\n",
    "autoencoder = Model(inputs=input_dim, outputs=decoded)\n",
    "\n",
    "encoder = Model(inputs=input_dim, outputs=encoder_output)\n",
    "\n",
    "autoencoder.compile(optimizer='adam', loss='mse')\n",
    "# training\n",
    "autoencoder.fit(train_X.values, train_X.values, epochs=50, batch_size=150, shuffle=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(15000, 200)\n",
      "(10000, 200)\n"
     ]
    }
   ],
   "source": [
    "new_train_feature = encoder.predict(train_X.values)\n",
    "new_test_feature = encoder.predict(test_X.values)\n",
    "print(new_train_feature.shape)\n",
    "print(new_test_feature.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5000, 361) (5000, 361) (5000, 361)\n",
      "(5000,) (5000,) (5000,)\n"
     ]
    }
   ],
   "source": [
    "train_x1 = train_X.iloc[0:5000,:]\n",
    "train_x2 = train_X.iloc[5000:10000,:]\n",
    "train_x3 = train_X.iloc[10000:15000,:]\n",
    "\n",
    "train_y1 = Y_train[0:5000]\n",
    "train_y2 = Y_train[5000:10000]\n",
    "train_y3 = Y_train[10000:15000]\n",
    "\n",
    "print(train_x1.shape,train_x2.shape,train_x3.shape)\n",
    "print(train_y1.shape,train_y2.shape,train_y3.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def SVM1(xTrain,yTrain,xTest):\n",
    "    clf = SVC(C=20, kernel='rbf',class_weight='balanced').fit(xTrain, yTrain)\n",
    "    print(\"SVM Mean Accuracy score = \",cross_val_score(clf,xTrain,yTrain).mean())\n",
    "    yPredSVM = clf.predict(xTest)\n",
    "    return clf,yPredSVM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SVM Mean Accuracy score =  0.9762007920674264\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "95"
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_svm1,yPredSVM1 = SVM1(train_x1, train_y1, test_X)\n",
    "np.sum(yPredSVM1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def SVM2(xTrain,yTrain,xTest):\n",
    "    clf = SVC(C=100, kernel='rbf', class_weight='balanced').fit(xTrain, yTrain)\n",
    "    print(\"SVM Mean Accuracy score = \",cross_val_score(clf,xTrain,yTrain).mean())\n",
    "    yPredSVM = clf.predict(xTest)\n",
    "    return clf,yPredSVM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SVM Mean Accuracy score =  0.8504009882297251\n"
     ]
    }
   ],
   "source": [
    "clf_svm2,yPredSVM2= SVM2(train_x2, train_y2, test_X)\n",
    "np.sum(yPredSVM2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def SVM3(xTrain,yTrain,xTest):\n",
    "    clf = SVC(C=20, kernel='rbf', class_weight='balanced').fit(xTrain, yTrain)\n",
    "    print(\"SVM Mean Accuracy score = \",cross_val_score(clf,xTrain,yTrain).mean())\n",
    "    yPredSVM = clf.predict(xTest)\n",
    "    return clf,yPredSVM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SVM Mean Accuracy score =  0.9662002773514925\n"
     ]
    }
   ],
   "source": [
    "clf_svm3,yPredSVM3= SVM3(train_x3, train_y3, test_X)\n",
    "np.sum(yPredSVM3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9034\n",
      "9034\n",
      "(24034, 361)\n",
      "(24034,)\n"
     ]
    }
   ],
   "source": [
    "xTrain = train_X\n",
    "yTrain = Y_train\n",
    "count=0\n",
    "for i in range(0,len(yPredSVM3)):\n",
    "    if(yPredSVM3[i] == yPredSVM2[i]) and (yPredSVM3[i] == yPredSVM1[i]):\n",
    "        count+=1                \n",
    "print(count)\n",
    "xTrainNew = np.ndarray(shape=(count,xTrain.shape[1]))\n",
    "yTrainNew = np.ndarray(shape=(count))\n",
    "xTestNew = np.ndarray(shape=(len(yPredSVM3)-count,xTrain.shape[1]))\n",
    "\n",
    "j = 0\n",
    "k = 0\n",
    "count = 0\n",
    "for i in range(0,len(yPredSVM3)):\n",
    "    if(yPredSVM3[i] == yPredSVM2[i]) and (yPredSVM3[i] == yPredSVM1[i]):\n",
    "        xTrainNew[j] = test_X.values[i]\n",
    "        yTrainNew[j] = yPredSVM3[i]\n",
    "        j += 1\n",
    "        count += 1                \n",
    "    else:\n",
    "        xTestNew[k]=test_X.values[i]\n",
    "        k += 1\n",
    "\n",
    "print(count)\n",
    "\n",
    "\n",
    "xTrainNew = np.concatenate((xTrainNew,xTrain.values))\n",
    "yTrainNew = np.concatenate((yTrainNew,yTrain.values))\n",
    "\n",
    "print(xTrainNew.shape)\n",
    "print(yTrainNew.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def SVM4(xTrain,yTrain,xTest):\n",
    "    clf = SVC(C=20, kernel='rbf', class_weight='balanced').fit(xTrain, yTrain)\n",
    "    print(\"SVM Mean Accuracy score = \",cross_val_score(clf,xTrain,yTrain).mean())\n",
    "    yPredSVM = clf.predict(xTest)\n",
    "    return clf,yPredSVM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SVM Mean Accuracy score =  0.9479071296521285\n"
     ]
    }
   ],
   "source": [
    "clf_svm4,yPredSVM4= SVM4(xTrainNew, yTrainNew, test_X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "420.0"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(yPredSVM4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# test_temp = test\n",
    "# print(test_temp.shape)\n",
    "# test_temp['y'] = yPredSVM4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# test_temp.to_csv('train_ssvm_xy.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def XGB(xTrain,yTrain,xTest):\n",
    "    xgb = XGBClassifier( n_estimators= 750, learning_rate=0.1, max_depth= 10, min_child_weight= 1, class_weight='balanced', gamma=0.9,\n",
    "                        subsample=0.9, colsample_bytree=0.8, objective= 'binary:logistic', nthread= -1, scale_pos_weight=1).fit(xTrain,yTrain)\n",
    "    print(\"XGB Mean Accuracy score = \",cross_val_score(xgb,xTrain,yTrain).mean())\n",
    "    yPredXGB = xgb.predict(xTest)\n",
    "    return xgb,yPredXGB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Program Files\\Anaconda3\\lib\\site-packages\\sklearn\\preprocessing\\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.\n",
      "  if diff:\n",
      "C:\\Program Files\\Anaconda3\\lib\\site-packages\\sklearn\\preprocessing\\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.\n",
      "  if diff:\n",
      "C:\\Program Files\\Anaconda3\\lib\\site-packages\\sklearn\\preprocessing\\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.\n",
      "  if diff:\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "XGB Mean Accuracy score =  0.8416666654346665\n",
      "88\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Program Files\\Anaconda3\\lib\\site-packages\\sklearn\\preprocessing\\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.\n",
      "  if diff:\n"
     ]
    }
   ],
   "source": [
    "xgb,yPredXGB= XGB(new_train_feature, Y_train, new_test_feature)\n",
    "print(np.sum(yPredXGB))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def LGB(xTrain,yTrain,xTest):\n",
    "    lgb = LGBMClassifier(n_estimators=750,\n",
    "                         learning_rate=0.1,\n",
    "                         num_leaves=25,\n",
    "                         class_weight='balanced',\n",
    "                         colsample_bytree=0.9,\n",
    "                         subsample=0.7,\n",
    "                         max_depth=10,\n",
    "                         reg_alpha=0.1,\n",
    "                         reg_lambda=0.1,\n",
    "                         min_split_gain=0.01,\n",
    "                         min_child_weight=1).fit(xTrain,yTrain)\n",
    "    print(\"LGB Mean Accuracy score = \",cross_val_score(lgb,xTrain,yTrain).mean())\n",
    "    yPredLGB = lgb.predict(xTest)\n",
    "    return lgb,yPredLGB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Program Files\\Anaconda3\\lib\\site-packages\\sklearn\\preprocessing\\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.\n",
      "  if diff:\n",
      "C:\\Program Files\\Anaconda3\\lib\\site-packages\\sklearn\\preprocessing\\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.\n",
      "  if diff:\n",
      "C:\\Program Files\\Anaconda3\\lib\\site-packages\\sklearn\\preprocessing\\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.\n",
      "  if diff:\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "LGB Mean Accuracy score =  0.8201335853200101\n",
      "444\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Program Files\\Anaconda3\\lib\\site-packages\\sklearn\\preprocessing\\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.\n",
      "  if diff:\n"
     ]
    }
   ],
   "source": [
    "lgb,yPredLGB= LGB(new_train_feature, Y_train, new_test_feature)\n",
    "print(np.sum(yPredLGB))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SVM Mean Accuracy score =  0.882266772090671\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "315"
      ]
     },
     "execution_count": 161,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf_svm5,yPredSVM5= SVM4(new_train_feature, Y_train, new_test_feature)\n",
    "np.sum(yPredSVM5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10000\n",
      "187\n"
     ]
    }
   ],
   "source": [
    "output = []\n",
    "for i in range(0,len(new_test_feature)):\n",
    "    count1 =0\n",
    "    count0 =0\n",
    "    if yPredSVM4[i] == 1:\n",
    "        count1 += 2\n",
    "    else:\n",
    "        count0 += 2\n",
    "    if yPredSVM5[i] == 1:\n",
    "        count1 += 1 \n",
    "    else:\n",
    "        count0 += 1\n",
    "    if yPredXGB[i] == 1:\n",
    "        count1 += 1\n",
    "    else:\n",
    "        count0 += 1\n",
    "    if yPredLGB[i] == 1:\n",
    "        count1 += 1\n",
    "    else:\n",
    "        count0 += 1\n",
    "\n",
    "    if count1 > count0 :\n",
    "        output.append(1)\n",
    "    else:\n",
    "        output.append(0)\n",
    "print(len(output))\n",
    "print(np.sum(output))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10000\n",
      "894\n"
     ]
    }
   ],
   "source": [
    "output1 = []\n",
    "for i in range(0,len(new_test_feature)):\n",
    "    if yPredSVM4[i] == 1 or yPredSVM5[i] == 1 or yPredXGB[i] == 1 or yPredLGB[i] ==1:\n",
    "        output1.append(1)\n",
    "    else:\n",
    "        output1.append(0)\n",
    "print(len(output1))\n",
    "print(np.sum(output1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(10000, 160)\n"
     ]
    }
   ],
   "source": [
    "test_temp = test\n",
    "print(test_temp.shape)\n",
    "test_temp['y'] = output1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "test_temp.to_csv('train_sssvm_s_xy.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(10000, 160)\n"
     ]
    }
   ],
   "source": [
    "test_temp = test\n",
    "print(test_temp.shape)\n",
    "test_temp['y'] = output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "test_temp.to_csv('train_sssvm_j_xy.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
